package cn.stylefeng.guns.schedule;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.guns.base.utils.Ao81Model;
import cn.stylefeng.guns.base.utils.Ao81Util;
import cn.stylefeng.guns.base.utils.DingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
 * @program: football_manage
 * @description:
 * @author: xiesm
 * @create: 2022-04-19 09:06
 **/
@Slf4j
//@Component
public class Ao85Schedule implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
//        new Thread(() -> {
//            List<String> nums = Arrays.asList("4", "9");
//            while (true) {
//                String mm = DateUtil.format(new Date(), "mm").substring(1);
//                if (nums.contains(mm)) {
//                    Integer ss = Integer.valueOf(DateUtil.format(new Date(), "ss"));
//                    test();
//                    ThreadUtil.sleep(60 - ss, TimeUnit.SECONDS);
//                } else {
//                    ThreadUtil.sleep(60000);
//                }
//            }
//        }).start();
    }

    public void test() {
        List<Ao81Model> datas = Ao81Util.parse();

        Ao81Model ao81Model = datas.get(0);
//        find(1, ao81Model.getCode1(), datas);
//        find(2, ao81Model.getCode2(), datas);
//        find(3, ao81Model.getCode3(), datas);
//        find(4, ao81Model.getCode4(), datas);
//        find(5, ao81Model.getCode5(), datas);
//        find(6, ao81Model.getCode6(), datas);
//        find(7, ao81Model.getCode7(), datas);
//        find(8, ao81Model.getCode8(), datas);
    }

    public static void main(String[] args) {
        Ao85Schedule ao81Schedule = new Ao85Schedule();
        ao81Schedule.test();
    }

    public void find(int i, Integer code, List<Ao81Model> datas) {
        List<Integer> nums = Arrays.asList(2, 3, 4, 5);
        for (int j = 0; j < nums.size(); j++) {
            Integer num = nums.get(j);
            Integer code2 = getCode(i, num, datas);
            if (Objects.equals(code, code2)) {
                code2 = getCode(i, num * 2, datas);
                if (Objects.equals(code, code2)) {
                    code2 = getCode(i, num * 2, datas);
                    if (Objects.equals(code, code2)) {
                        String content = StrUtil.format("issue:{},type:1,num:{}", datas.get(0).getIssue(), i);
//                        log.info(content);
                        DingUtil.send(content, "1");
                    }
                }
            }
            Integer newCode = getCode(i, num, datas);
            int total = code - newCode;
            if (Objects.equals(code, newCode + total)) {
                code2 = getCode(i, num * 2, datas);
                if (Objects.equals(newCode, code2 + total)) {
                    code2 = getCode(i, num * 2, datas);
                    if (Objects.equals(newCode, code2 + total)) {
                        String content = StrUtil.format("issue:{},type:2,num:{}", datas.get(0).getIssue(), i);
//                        log.info(content);
                        DingUtil.send(content, "1");
                    }
                }
            }
        }

    }

    public Integer getCode(int i, int num, List<Ao81Model> datas) {
        Ao81Model ao81Model = datas.get(num);
        Integer code2 = 0;
        switch (i) {
            case 1:
                code2 = ao81Model.getCode1();
                break;
            case 2:
                code2 = ao81Model.getCode2();
                break;
            case 3:
                code2 = ao81Model.getCode3();
                break;
            case 4:
                code2 = ao81Model.getCode4();
                break;
            case 5:
                code2 = ao81Model.getCode5();
                break;
            case 6:
                code2 = ao81Model.getCode6();
                break;
            case 7:
                code2 = ao81Model.getCode7();
                break;
            case 8:
                code2 = ao81Model.getCode8();
                break;
        }
        return code2;
    }


}
